package cn.com.bluemoon.daps.common.toolkit;

import com.alibaba.druid.util.HiveUtils;
import com.alibaba.druid.util.Utils;

import java.util.HashSet;
import java.util.Set;

/**
 * hive工具
 *  @author Jarod.Kong
 *  @date 2021/1/22 14:48
 */
public final class HiveUtil extends HiveUtils {
    private static Set<String> keywords;

    private HiveUtil() {
    }

    public static boolean isKeyword(String keyword) {
        if (keyword == null) {
            return false;
        }

        String tableLower = keyword.toLowerCase();

        Set<String> keywordSet = keywords;

        if (keywordSet == null) {
            keywordSet = new HashSet<String>();
            loads(keywordSet);
            keywords = keywordSet;
        }

        return keywordSet.contains(tableLower);
    }

    public static void loads(Set<String> keywordSet) {
        Utils.loadFromFile("META-INF/druid/parser/hive/keywords", keywordSet);
    }
}

